﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace CXMLStudioIDE.Common.Entities
{
    public class BusinessEntity : Entity
    {
        #region Declarations

        private BusinessEntityCollection _Entities;
        private BusinessEntity _Parent;
        private Hashtable _ControlBindings;
        private Project _ParentProject;
        private EntityType _EntityType;
        private EntityTypeVersions _EntityTypeVersions;
        private EntityVersion _EntityVersion;
        private EntityInstanceCollection _Instances;

        #endregion

        #region Constructors
        public BusinessEntity()
        {
            _EntityType = new EntityType();
            _EntityTypeVersions = new EntityTypeVersions();
            _EntityVersion = new EntityVersion();
            _Instances = new EntityInstanceCollection();
        }
        public BusinessEntity(string Name, int ID, EntityType inEntityType, EntityTypeVersions inETV,
            EntityVersion inEntityVersion)
        {
            this.Name = Name;
            this._EntityType = inEntityType;
            this._EntityTypeVersions = inETV;
            this._EntityVersion = inEntityVersion;
        }
        #endregion
        #region Public Properties
        public EntityVersion EntityVersion
        {
            get { return _EntityVersion; }
            set { _EntityVersion = value; }
        }
        public EntityInstanceCollection EntityInstance
        {
            get { return _Instances; }
            set { _Instances = value; }
        }
        public EntityTypeVersions EntityTypeVersions
        {
            get { return _EntityTypeVersions; }
            set { _EntityTypeVersions = value; }
        }
        public EntityType EntityType
        {
            get { return _EntityType; }
            set { _EntityType = value; }
        }

        public Project ParentProject
        {
            get { return _ParentProject; }
            set { _ParentProject = value; }
        }

        public Hashtable ControlBindings
        {
            get { return _ControlBindings; }
            set { _ControlBindings = value; }
        }

        public BusinessEntity Parent
        {
            get { return _Parent; }
            set { _Parent = value; }
        }

        public BusinessEntityCollection Entities
        {
            get { return _Entities; }
            set { _Entities = value; }
        }

        public int TreeViewId { get; set; }

        #endregion

        #region methods
        public BusinessEntity GetInnerBusinessEntityByName(string sZ_BusinessEntityName)
        {
            foreach (BusinessEntity b in _Entities)
            {
                if (b.Name.Equals(sZ_BusinessEntityName))
                {
                    return b;
                }
            }
            return null;
        }

        public override string ToString()
        {
            return _EntityType.EntityTypeContextName + "->" + _EntityVersion.FullVersion + "->" + Name;
        }
        #endregion
    }
}
